import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution310_2 {

    public static void main(String args[]) {
        Solution310_2 s = new Solution310_2();
        s.dfs(0, new int[]{1, 2});
    }

    public void dfs(int n, int[] nums) {
        if (n == nums.length) {
            System.out.println(Arrays.toString(nums));
            return;
        }

        for (int i = n; i < nums.length; i++) {
            swap(nums, n, i);
            dfs(n + 1, nums);
            swap(nums, n, i);
        }
    }

    public void swap(int[] nums, int a, int b) {
        int t = nums[a];
        nums[a] = nums[b];
        nums[b] = t;
    }

}
